package java_thinking.unit_19._19_1_6;

import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.Set;
import java.util.TreeSet;


/**
 * @Desc:
 *      javac Reflection.java
 *      javap Explore.class
 *      1.验证Enum的values()方法是编译器添加的static 方法
 *      2.编译的时候还添加了 valueOf(java.lang.String);与Enum自身的方法区别是这方法只有一个参数
 *      3.由于擦除效应，反编译无法得到Enum的完整信息，所以它展示的Explore父类只是一个原始的Enum，而非
 *      事实上的Enum<Explore>
 * @author: cww
 * @DateTime: 2019/5/22 16:03
 */

enum Explore { HERE, THERE}

public class Reflection {
    public static Set<String> analyze(Class<?> enumClass) {
        System.out.println("----- Analyzing " + enumClass + "-------");
        System.out.println("Interfaces:");
        for (Type type : enumClass.getGenericInterfaces()) {
            System.out.println(type);
        }
        System.out.println("Base: " + enumClass.getSuperclass());
        System.out.println("Methods:");
        Set<String> methods = new TreeSet<>();
        for (Method m : enumClass.getMethods()) {
            methods.add(m.getName());
        }
        System.out.println(methods);
        return methods;
    }

    public static void main(String[] args) {
        Set<String> exploreMethods = analyze(Explore.class);
        Set<String> enumMethods = analyze(Enum.class);
        System.out.println("Explore.containsAll(Enum)? " + exploreMethods.containsAll(enumMethods));
        System.out.println("Explore.removeAll(Enum): ");
        exploreMethods.removeAll(enumMethods);
        System.out.println(exploreMethods);
    }
}
